package client_v2;

import client.Client;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @file Client.java
 *
 * @version 0.2
 * @author James Dibble 10009689
 */
public class Client_V2 {
    static Client client;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scnrInput = new Scanner(System.in);
        String strServerIP, strServerPort;

        System.out.print("Welcome to File Client\n\nIP Address: ");
        strServerIP = scnrInput.nextLine();
        System.out.print("Server Port: ");
        strServerPort = scnrInput.nextLine();

        if (strServerIP.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b")) {
            if(strServerPort.matches("\\b\\d{1,5}\\b")){
                int intPort = Integer.parseInt(strServerPort);
                try {
                    client = new Client(strServerIP, intPort, Client.Client_Type.FILE_CLIENT);
                } catch (UnknownHostException ex) {
                    ex.printStackTrace(System.out);
                    System.out.println("Server could not be found at this IP and Port.  Closing..");
                } catch (IOException ex) {
                    ex.printStackTrace(System.out);
                    System.out.println("General Socket Error.  Closing..");
                }
            }
            else{
                System.out.println(String.format("%s is not a valid Port.  Closing...",
                                                 strServerPort));
            }
        }
        else {
            System.out.println(String.format("%s is not an IP Address.  Closing...",
                               strServerIP));
        }
    }
}